package com.capinfo.accounting.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.poi.hssf.eventusermodel.AbortableHSSFListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.capinfo.accumulation.model.accounting.mybist.GB_JZPZXX;
import com.capinfo.accumulation.model.accounting.mybist.PZHZ;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.GB_JZPZXXServiceI;
import com.capinfo.accumulation.service.accounting.mybits.PZHZServiceI;
import com.capinfo.commons.project.model.security.SystemUser;
import com.capinfo.accumulation.model.pagemodel.Json;

import com.capinfo.components.security.web.utils.WebRequestUtils;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *  @author zxl
 */
@Controller
@RequestMapping("/business/accounting/pZHZ")
public class PZHZController extends BaseController {
	@Autowired
	public PZHZServiceI pZHZService;
	
	@Autowired
	public GB_JZPZXXServiceI gB_JZPZXXService;
	//以汇总的
	@RequestMapping("/dataGrid.shtml")
	@ResponseBody
	public DataGrid yidataGrid(@RequestParam  Map param) {
		return pZHZService.findbyByGrid(param);
	}
	
	
	@RequestMapping("/add.shtml")
	@ResponseBody
	public Json add(@RequestParam Map param ,HttpSession session,NativeWebRequest request) {
		
		SystemUser user = (SystemUser)WebRequestUtils.retrieveSecureUser(request);
		PZHZ pz=new PZHZ();
		GB_JZPZXX gb=new GB_JZPZXX();
		Map map= new HashMap();
	
		Json j = new Json();
		
		
    	   map.put("PZLB",param.get("PZLB"));
    	   map.put("HSDW",param.get("HSDW"));
    	   map.put("ZTDM",param.get("ZTBH"));
    	   map.put("ZDRQ",param.get("ZDRQ_EQ_DATE"));
    	   
    	    gB_JZPZXXService.select(map);
    	    
    	    gB_JZPZXXService.PzhzBiaoJiupdate(map);
    	  
		return j;
	}


	@RequestMapping("/edit.shtml")
	@ResponseBody
	public Json edit(PZHZ t , HttpSession session,NativeWebRequest request) {
		
		SystemUser user = (SystemUser)WebRequestUtils.retrieveSecureUser(request);
		Json j = new Json();
		try {
			
			pZHZService.updateByPrimaryKeySelective(t);
			j.setSuccess(true);
			j.setMsg("��ӳɹ���");
			j.setObj(t);
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/delete.shtml")
	@ResponseBody
	public Json delete(String id) {
		
		pZHZService.pzhzdelete(id);
		String[] a=id.split(",");
		
		System.out.println(a);
		
		for(int i=0;i<a.length;i++){
			gB_JZPZXXService.qxhzupdate(a[i]);
		}
		Json j = new Json();
		
		
		return j;
	}

	@RequestMapping("/selectByid.shtml")
	@ResponseBody
	public PZHZ selectByid(String id) {
		return pZHZService.selectByPrimaryKey(id);
	}
	
	
	/**
	 * 
	 * 走到待汇总
	 */
	@RequestMapping("/manager.shtml")
	public String manager(Model mdl) {
		List list=gB_JZPZXXService.xlhzselect();
		mdl.addAttribute("list",list);
		return "/business/accounting/pzhz/pzhz";
	}
	/**
	 * 
	 * 走到以汇总
	 */
	@RequestMapping("/yihuizong.shtml")
	public String yihuizong() {
		return "/business/accounting/pzhz/yihuipzhz";
	}
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/addPage.shtml")
	public String addPage(HttpServletRequest request) {
		PZHZ pZHZ  = new PZHZ();
		request.setAttribute("pZHZ", pZHZ);
	return "/pZHZ/pZHZAdd";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/editPage.shtml")
	public String editPage(String id ,HttpServletRequest request) {
		PZHZ pZHZ = this.pZHZService.selectByPrimaryKey(id);
		request.setAttribute("pZHZ", pZHZ);
		return "/pZHZ/pZHZEdit";
	}
	
	/**
	 * 
	 * @return
	 */
	@RequestMapping("/viewPage.shtml")
	public String viewPage(String id ,HttpServletRequest request) {
		PZHZ pZHZ = this.pZHZService.selectByPrimaryKey(id);
		request.setAttribute("pZHZ", pZHZ);
		return "/pZHZ/pZHZView";
	}
}
